//
//  HomeMessageCell.m
//  PPDL
//
//  Created by 王洋 on 2019/7/23.
//  Copyright © 2019 王洋. All rights reserved.
//

#import "HomeMessageCell.h"

@interface HomeMessageCell ()<GYRollingNoticeViewDataSource, GYRollingNoticeViewDelegate>

@property (nonatomic, strong) GYRollingNoticeView *noticeView;

@property (nonatomic, strong) NSMutableArray *msgArray;
@end

@implementation HomeMessageCell

- (void)awakeFromNib {
    [super awakeFromNib];

    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.backgroundColor = [UIColor whiteColor];
    self.msgArray = @[].mutableCopy;
    [self layout];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        

    }
    return self;
}

- (void)layout {
    
    [self addSubview:self.noticeView];
    
    self.noticeView.frame = CGRectMake(50, 0, TTScreenWidth - 120, 50);
    
    
}

- (void)fillCellWithList:(NSMutableArray *)msgList {
    
//    self.msgArray = msgList;
    
    self.msgArray = @[@"22222222",@"3333333333333",@"55555555555555555555555"].mutableCopy;

    [self.noticeView reloadDataAndStartRoll];

//    if (msgList.count == 0) {
//
//        [msgList addObject:@"无最新消息"];
//        self.scrollText.textDataArr = msgList;
//
//    } else if (msgList.count == 1) {
//
//        self.scrollText.textDataArr = msgList;
//
//
//    } else {
//        self.scrollText.textDataArr = msgList;
//    }
//
//    [self.scrollText startScrollTopToBottomWithSpace];

}

- (NSInteger)numberOfRowsForRollingNoticeView:(GYRollingNoticeView *)rollingView
{
    
    return self.msgArray.count;
    
}
- (__kindof GYNoticeViewCell *)rollingNoticeView:(GYRollingNoticeView *)rollingView cellAtIndex:(NSUInteger)index
{
    
    GYNoticeViewCell *cell = [rollingView dequeueReusableCellWithIdentifier:@"GYNoticeViewCell"];
    cell.textLabel.text = [NSString stringWithFormat:@"%@", self.msgArray[index]];
    cell.contentView.backgroundColor = [UIColor whiteColor];

    return cell;
}

- (void)didClickRollingNoticeView:(GYRollingNoticeView *)rollingView forIndex:(NSUInteger)index
{
    NSLog(@"点击的index: %lu", (unsigned long)index);
}

- (GYRollingNoticeView *)noticeView {
    
    if (!_noticeView) {
        _noticeView = [[GYRollingNoticeView alloc]init];
        _noticeView.dataSource = self;
        _noticeView.delegate = self;
        _noticeView.backgroundColor = [UIColor lightGrayColor];
        
        
        [_noticeView registerClass:[GYNoticeViewCell class] forCellReuseIdentifier:@"GYNoticeViewCell"];
        
    }
    return _noticeView;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
